﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DirectorySlicer
{
    /// <summary>
    /// logger class
    /// </summary>
    public sealed class Logger
    {
        private static readonly Logger instanceOfLogger = new Logger();

        public delegate void UpdateLogCallback(string strMessage);
        public static void Log(string meldung)
        {
            instanceOfLogger.NeueMeldung(meldung);
        }

        public delegate void UpdateProgressSettingCallback(int max);
        public static void progressBarSet(int max)
        {
            instanceOfLogger.set(max);
        }

        public delegate void UpdateProgressCallback();
        public static void progressAdd()
        {
            instanceOfLogger.progress();
        }

        /// <summary>
        /// Set the Logger, which is to be used for output
        /// </summary>
        /// <param name="logger"></param>
        public static void SetLogger(TextBox logger, ProgressBar bar)
        {
            instanceOfLogger.logBox = logger;
            instanceOfLogger.progressBar = bar;
        }

        private TextBox logBox = null;
        private ProgressBar progressBar = null;
        
        private void NeueMeldung(string meldung)
        {
            if (this.logBox != null)
            {
                logBox.AppendText(meldung + Environment.NewLine);
                logBox.SelectionStart = logBox.Text.Length;
                logBox.ScrollToCaret();
            }
        }

        private void set(int max)
        {
            progressBar.Maximum = max;
        }

        private void progress()
        {
            progressBar.PerformStep();
        }
    }

}
